package com.teach;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class HttpServer2 {
	public static void main(String[] args)throws Exception {
		
	}
	
	private static class HttpOne implements Runnable{
		private Socket client;
		public HttpOne (Socket client) {
			super();
		}
		
		public void run() {
			InputStream in = client.getInputStream();
			BufferedReader request = new BufferedReader(new InputStreamReader(in,"UTF-8"));
			OutputStream out = client.getOutputStream();
			PrintWriter response = new PrintWriter(new OutputStreamWriter(out,"UTF-8"));
			String line = null;
			while(!" ".equals(line=request.readLine())) {
				System.out.println(line);
			}
			System.out.println("读取完成");
			
			
			response.println("HTTP/1.1 200 OK");
			response.println("Content-Type:text/html;charset=UTF-8");
			response.println();//空行后面是响应正文
			response.println("<h1>你好，这是我写的</h1>");
			response.flush();
			System.out.println("发送完成");
		}
	}

}
